import sys

from PyQt6 import QtCore
from PyQt6.QtWidgets import QApplication,QMainWindow
from login import *
from PyQt6.QtCore import Qt
from PyQt6.QtGui import QMouseEvent, QCursor
from Ui_login import Ui_MainWindow
class MainWindows(QMainWindow,Ui_MainWindow):
    def __init__(self,parent=None):
        super(MainWindows,self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.WindowType.FramelessWindowHint)
        # self.setAttribute(Qt.WA_TranslucentBackground)#pyqt6中没有
        self.setWindowOpacity(1)  # 设置窗口透明度为0.5
        #按钮
        self.close_pushButton.clicked.connect(self.close)
        self.hidden_pushButton.clicked.connect(self.showMinimized)

    #窗口拖动
    def mousePressEvent(self, event):
        if event.button() == Qt.MouseButton.LeftButton:
            self.m_flag = True
            self.m_Position = event.globalPosition() - QtCore.QPointF(self.pos())
            event.accept()
            self.setCursor(QCursor(Qt.CursorShape.OpenHandCursor))

    def mouseMoveEvent(self, QMouseEvent):
        if Qt.MouseButton.LeftButton and self.m_flag:
            self.move((QMouseEvent.globalPosition() - self.m_Position).toPoint())
            QMouseEvent.accept()

    def mouseReleaseEvent(self, QMouseEvent):
        self.m_flag = False
        self.setCursor(QCursor(Qt.CursorShape.ArrowCursor))

if __name__=="__main__":
    app=QApplication(sys.argv)
    mywin=MainWindows()
    mywin.show()
    sys.exit(app.exec())#在 PyQt6 中，QApplication 对象没有 exec_ 属性。你应该使用 exec() 方法来启动事件循环。